package com.hhj.demo.base;

import lombok.Data;

import java.io.Serializable;

/**
 * @description:
 * @author: KING
 * @create: 2018-07-27 13:38
 **/
@Data
public class Result<T> implements Serializable {

    /**
     * 是否请求成功
     */
    private Boolean success;

    /**
     * 返回状态码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回对象
     */
    private T data;

    /**
     * 总记录数
     */
    private Long count;

    private Result() {
    }

    private Result(Boolean bool, Integer code) {
        this.success = bool;
        this.code = code;
    }

    private Result(Boolean bool, Integer code, T data) {
        this.success = bool;
        this.code = code;
        this.data = data;
    }

    private Result(Boolean bool, Integer code, String resultEnums, T data, Long count) {
        this.success = bool;
        this.code = code;
        this.message = resultEnums;
        this.data = data;
        this.count = count;
    }

    public static Result success() {
        return new Result(Boolean.TRUE, 200);
    }

    public static Result success(Object data) {
        return new Result(Boolean.TRUE, 200, data);
    }


    public static Result error() {
        return new Result(Boolean.FALSE, 500);
    }

    public static Result error(String msg) {
        return new Result(Boolean.FALSE, 500, msg, null, null);
    }


}
